# Makefile for ccal
IS_AS:=true
ifeq ($(IS_AS),true)
ALCHEMY_HOME:=$(HOME)/alchemy-ubuntu-v0.5a
ASC:=$(ALCHEMY_HOME)/bin/asc.jar 
PATH:=$(ALCHEMY_HOME)/achacks:$(ALCHEMY_HOME)/bin/llvm-gcc4-ubuntu-install/libexec/gcc/i686-pc-linux-gnu/4.2.1/:$(ALCHEMY_HOME)/bin:$(PATH)
#SWFBRIDGE:=$(ALCHEMY_HOME)/bin/swfbridge
FLEX_HOME:=$(HOME)/flex_sdk_4.5
FLASHPLAYER:=$(FLEX_HOME)/bin/flashplayerdebugger
MXMLC:=$(FLEX_HOME)/bin/mxmlc
ADL:=$(FLEX_HOME)/bin/adl
SWF:=test.swf
AS3_PATH:=.
AS3:=$(AS3_PATH)/Test.as
SWC:=ccal.swc



# If a different C++ compiler is to be used, specify it below
#CXX=cc
CXX:=ALCHEMY_HOME=$(ALCHEMY_HOME)  $(ALCHEMY_HOME)/achacks/g++
CC:=$(CXX)
else
CXX=g++
CC:=$(CXX)
endif


# If you don't want to use the year cache, comment the following line
CXXFLAGS += -DUSE_YEARCACHE

# If the compiler doesn't use namespace, uncomment the following line
#CXXFLAGS += -DNO_NAMESPACE

# Binary installation directory
BINDIR=/usr/local/bin

# Man page installation directory
MANDIR=/usr/local/man

# If install is not available, use cp instead
INSTALL=install -c

COMPONENTS:= \
	lunaryear \
	mphases \
	htmlmonth \
	psmonth \
	moonphase \
	misc \
	solarterm \
	tt2ut \
	novas \
	novascon \
	nutation \
	solsys3 \
	yearcache\

ifeq ($(IS_AS),true)
	COMPONENTS:=$(COMPONENTS) ccal
endif
#	array

# If you don't want to use the year cache, comment the previous line
# End of list

# End of configuration parameters

OBJS=$(COMPONENTS:%=%.o)

#CFLAGS += -O2
CFLAGS += -D USE_YEARCACHE
ifeq ($(IS_AS),true)
CXXFLAGS +=-D as_api -O2 -Wall
else
CXXFLAGS +=-D test_ccal -O2 -Wall
endif


all: $(SWF) ccal
ifeq ($(IS_AS),true)
	$(ADL) test.xml
else
	./ccal
endif


$(SWF): $(SWC) $(AS3)
ifeq ($(IS_AS),true)
	$(MXMLC) -strict=true  -tools-locale en_US -omit-trace-statements=false -verbose-stacktraces=true -debug=true -source-path=$(AS3_PATH) -library-path+=$(SWC) $(AS3) -o $(SWF)
endif

$(SWC): $(OBJS)
ifeq ($(IS_AS),true)
	ASC=$(ASC) $(CC) $(OBJS) $(CFLAGS) -swc -o $(SWC)
endif

.c.o:
ifeq ($(IS_AS),true)
	$(CC) $(CFLAGS) -c $<
else
	$(CC) $(CXXFLAGS) -c $<
endif


ccal: $(OBJS) ccal.o
ifeq ($(IS_AS),false)
	$(CXX) $(CXXFLAGS) -o $@ $^ -lm
endif


.PHONY : clean

install:	ccal
	./mkinstalldirs $(BINDIR)
	$(INSTALL) ccal $(BINDIR)
	$(INSTALL) ccalpdf $(BINDIR)

install-man:
	./mkinstalldirs $(MANDIR)/man1
	$(INSTALL) -m 0644 ccal.1 $(MANDIR)/man1
	$(INSTALL) -m 0644 ccalpdf.1 $(MANDIR)/man1

clean:
	$(RM) *.o *.exe *.swf *.bc core ccal *.swc
